<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;

class DecryptParams
{
    public function handle(Request $request, Closure $next)
    {
        // decrypt request param
        $encrypted = $request->input('DATA');
        $plainttext = openssl_decrypt(base64_decode($encrypted), "AES-128-CBC", env('AES_KEY'), OPENSSL_RAW_DATA, env('AES_IV'));
        $swap = json_decode($plainttext, true);
        $request->replace($swap);
        return $next($request);
    }
}
